<template>
  <div id="recruitTableJH">
    {{ rowData[columnName] }}
    <el-popover class="item"
      :open-delay="600"
      placement="top"
      trigger="hover"
      content="该单位在历年招聘人员信息库中不存在"
      v-if="!testTable||testTable.length===0||!testTable.find(item=>item.unitName===rowData.unitName)">
      <el-button slot="reference" type="text" icon="el-icon-warning" />
    </el-popover>
    <template v-else-if="columnName!=='unitName'">
      <el-popover class="item"
        :open-delay="600"
        placement="top"
        trigger="hover"
        :content="contentText"
        @show="contentTextFun"
        v-if="testTable.find(item=>item.unitName===rowData.unitName)[columnName]!==rowData[columnName]">
        <el-button slot="reference" type="text" icon="el-icon-warning" />
      </el-popover>
    </template>
  </div>
</template>
<script>
export default {
  props: {
    testTable: null,
    columnName: '',
    rowData: null,
    theYear: null,
    unitBeijing: '',
    education: '',
    unitId: null,
    inPost: null,
    inBeijing: null
  },
  data () {
    return {
      contentText: '加载中...'
    }
  },
  watch: {
    testTable (val) {
    },
    columnName (val) {
    },
    rowData (val) {
    },
    theYear (val) {
    }
  },
  methods: {
    contentTextFun () {
      const num = this.testTable.find(item => item.unitName === this.rowData.unitName)[this.columnName]
      const educationArr = ['大专', '本科生', '硕士研究生', '博士研究生', '其他']
      const param = {
        theYear: this.theYear,
        unitBeijing: parseInt(this.unitBeijing),
        unitName: this.rowData.unitName,
        theType: 1,
        unitId: this.unitId,
        education: educationArr[this.columnName.slice(-1) - 1],
        inPost: this.inPost,
        inBeijing: this.inBeijing
      }
      // 如果为表4，则不传education
      const arr = ['count1', 'count2', 'count3', 'inPostCount1', 'inPostCount2', 'inPostCount3']
      if (arr.includes(this.columnName)) {
        param.education = ''
      }
      if (this.columnName !== 'unitName' && num > 0) {
        this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusUnit/getPersons`, param).then(response => {
          console.log(response.data.success)
          console.log(num, response.data.result)
          if (response.data.success === true) {
            let str = ''
            response.data.result.forEach((item, index) => {
              if (index === response.data.result.length - 1) {
                str += item.realName + `（${item.idCardNo}）`
              } else {
                str += item.realName + `（${item.idCardNo}）、`
              }
            })
            this.contentText = '在历年招聘人员信息库中为' + num + '人：' + str
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      } else {
        this.contentText = '在历年招聘人员信息库中为0人'
      }
    },
    fColumnName () {
      switch (this.columnName) {
        case 'countLastYearBeijing1':
          return '京内生源大专'
        case 'countLastYearBeijing2':
          return '京内生源本科生'
        case 'countLastYearBeijing3':
          return '京内生源硕士研究生'
        case 'countLastYearBeijing4':
          return '京内生源博士研究生'
        case 'countLastYearBeijing5':
          return '京内生源其他'
        case 'countLastYear1':
          return '京外生源大专'
        case 'countLastYear2':
          return '京外生源本科'
        case 'countLastYear3':
          return '京外生源硕士研究生'
        case 'countLastYear4':
          return '京外生源博士研究生'
        case 'countLastYear5':
          return '京外生源其他'
        case 'count1':
          return '实际接收落户人数'
        case 'count2':
          return '实际接收落户人数'
        case 'count3':
          return '实际接收落户人数'
        case 'inPostCount1':
          return '截止目前在岗人数'
        case 'inPostCount3':
          return '截止目前在岗人数'
        case 'inPostCount2':
          return '截止目前在岗人数'
        case 'count111':
          return '实际接收人数'
        case 'count112':
          return '实际接收人数'
        case 'count113':
          return '实际接收人数'
        case 'count114':
          return '实际接收人数'
        case 'count115':
          return '实际接收人数'
        case 'count121':
          return '目前在岗人数'
        case 'count122':
          return '目前在岗人数'
        case 'count123':
          return '目前在岗人数'
        case 'count124':
          return '目前在岗人数'
        case 'count125':
          return '目前在岗人数'
        case 'count211':
          return '实际接收人数'
        case 'count212':
          return '实际接收人数'
        case 'count213':
          return '实际接收人数'
        case 'count214':
          return '实际接收人数'
        case 'count215':
          return '实际接收人数'
        case 'count221':
          return '目前在岗人数'
        case 'count222':
          return '目前在岗人数'
        case 'count223':
          return '目前在岗人数'
        case 'count224':
          return '目前在岗人数'
        case 'count225':
          return '目前在岗人数'
        case 'count311':
          return '实际接收人数'
        case 'count312':
          return '实际接收人数'
        case 'count313':
          return '实际接收人数'
        case 'count314':
          return '实际接收人数'
        case 'count315':
          return '实际接收人数'
        case 'count321':
          return '目前在岗人数'
        case 'count322':
          return '目前在岗人数'
        case 'count323':
          return '目前在岗人数'
        case 'count324':
          return '目前在岗人数'
        case 'count325':
          return '目前在岗人数'
      }
    }
  },
  mounted () {
  }
}
</script>
